using Godot;
using System;

public partial class CharacterBody2d2 : CharacterBody2D
{
	NavigationAgent2D nav;

	public override void _Ready()
	{
		base._Ready();
		// 获取节点
		nav = GetNode<NavigationAgent2D>("NavigationAgent2D");
	}

	public override void _PhysicsProcess(double delta)
	{
		// 设置导航目标点为鼠标位置
		nav.TargetPosition = GetGlobalMousePosition();
		// 获取移动方向
		Vector2 direction = (nav.GetNextPathPosition() - this.Position).Normalized();
		// 设置移动速度
		Velocity = direction * 300;
		MoveAndSlide();
	}
}
